package com.example.music.controller;

import com.example.commonutils.R;
import com.example.music.model.request.SingerRequest;
import com.example.music.service.SingerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @ClassName AdminController
 * @Author: wx
 * @Create: 2022-10-04  17:12
 * @Description TODO
 * @Version: 1.0
 **/
@Api(description="添加歌手操作")
@RestController
@CrossOrigin //解决跨域问题
public class SingerController {

    @Autowired
    private SingerService singerService;


    // 添加歌手
    @ApiOperation("添加歌手")
    @PostMapping("/singer/add")
    public R addSinger(@RequestBody SingerRequest addSingerRequest) {
        return singerService.addSinger(addSingerRequest);
    }

    // 删除歌手
    @ApiOperation("删除歌手")
    @GetMapping("/singer/delete")
    public R deleteSinger(@RequestParam int id) {
        return singerService.deleteSinger(id);
    }

    // 返回所有歌手
    @ApiOperation("返回所有歌手")
    @GetMapping("/singer")
    public R allSinger() {
        return singerService.allSinger();
    }

    // 根据歌手名查找歌手
    @ApiOperation("根据歌手名查找歌手")
    @GetMapping("/singer/name/detail")
    public R singerOfName(@RequestParam String name) {
        return singerService.singerOfName(name);
    }

    // 根据歌手性别查找歌手
    @ApiOperation("根据歌手性别查找歌手")
    @GetMapping("/singer/sex/detail")
    public R singerOfSex(@RequestParam int sex) {
        return singerService.singerOfSex(sex);
    }

    /**
     * 更新歌手信息
     **/
    @ApiOperation("更新歌手信息")
    @PostMapping("/singer/update")
    public R updateSingerMsg(@RequestBody SingerRequest updateSingerRequest) {
        return singerService.updateSingerMsg(updateSingerRequest);
    }

    // 更新歌手头像
    @ApiOperation("更新歌手头像")
    @PostMapping("/singer/avatar/update")
    public R updateSingerPic(@RequestParam("file") MultipartFile avatorFile, @RequestParam("id") int id) {
        return singerService.updateSingerPic(avatorFile, id);
    }
}
